package com.wikitude.example;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * simple Activity for displaying information about a specific poi
 * gets the information about a poi from an intent
 */
public class PoiDetailActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.poi_detail);
			
		String name = this.getIntent().getExtras().getString("POI_NAME");
		String desc = this.getIntent().getExtras().getString("POI_DESC");
		String photo = this.getIntent().getExtras().getString("POI_PHOTO");/////////////Steve
		
			((TextView) this.findViewById(R.id.tvPoiName)).setText(name);
			((TextView) this.findViewById(R.id.tvPoiDesc)).setText(desc);
			((ImageView) this.findViewById(R.id.image_view1)).setImageDrawable(getPhoto(photo));/////////////Steve

	}
	//////////////////////////////////////////////////////////////////Steve
	public Drawable getPhoto(String photoURL) {
		try {
			InputStream is = (InputStream) fetch(photoURL);
			Drawable d = Drawable.createFromStream(is, "src");
			return d;
		} catch (MalformedURLException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public Object fetch(String myURL) throws MalformedURLException,IOException {
		URL url = new URL(myURL);
		Object content = url.getContent();
		return content;
	}
	//////////////////////////////////////////////////////////////////Steve/
}
